/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package filmlibrary.web;



import java.util.List;
import java.util.logging.Logger;
import javax.faces.bean.ManagedBean;
import filmlibrary.orm.*;

import filmlibrary.orm.classes.Genres;
import filmlibrary.orm.classes.Quality;

import java.util.Arrays;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author karol
 */
@ManagedBean
@RequestScoped
public class AddBean implements java.io.Serializable {

    private static final Logger logger = Logger.getLogger("filmlibrary.web.AddBean");
    ORMHelper orm = new ORMHelper();
    String titleOrg;
    String titleEn;
    String titlePl;
    short year;
    private String[] genre = {""};
    int fileSize;
    String quality;
    List<Genres> genresdb;

    /** Creates a new instance of AddBean */
    public AddBean() {
        logger.info("konstruktor add");
        titleOrg="";
        titleEn="";
        titlePl="";
        year = 1990;        
        
        quality="";
        genresdb = orm.getGenres();
        
    }
    public String add(){
        
        orm.addFilm(new SessionBean().getLogin(), quality, titleOrg, titleEn, titlePl, year, fileSize, genre);
        return "myFilms.xhtml?faces-redirect=true";

    }

    
    public List<Quality> getQualitiesFromDB() {
        
        List<Quality> q = orm.getQualities();
        
        return q;
    }
    


    public String[] getGenre() {
        return (String[]) genre.clone();
    }
    public String getGenreInString() {
        return Arrays.toString(genre);
    }

    public void setGenre(String genre[]) {
        this.genre = (String[]) genre.clone();
    }

    public String getQuality() {
        return quality;
    }

    public void setQuality(String quality) {
        this.quality = quality;
    }

    public int getFileSize() {
        return fileSize;
    }

    public void setFileSize(int fileSize) {
        this.fileSize = fileSize;
    }

    
    public String getTitleEn() {
        return titleEn;
    }

    public void setTitleEn(String titleEn) {
        this.titleEn = titleEn;
    }

    public String getTitleOrg() {
        return titleOrg;
    }

    public void setTitleOrg(String titleOrg) {
        this.titleOrg = titleOrg;
    }

    public String getTitlePl() {
        return titlePl;
    }

    public void setTitlePl(String titlePl) {
        this.titlePl = titlePl;
    }

    public short getYear() {
        return year;
    }

    public void setYear(short year) {
        this.year = year;
    }

    public List<Genres> getGenresdb() {
        return genresdb;
    }             
}